package qlsl.androiddesign.http.service.subservice;

import java.util.HashMap;
import java.util.List;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import qlsl.androiddesign.constant.WhatConstant;
import qlsl.androiddesign.handler.subhandler.HttpHandler;
import qlsl.androiddesign.http.HttpListener;
import qlsl.androiddesign.http.service.baseservice.BaseService;
import qlsl.androiddesign.http.xutils.HttpProtocol;
import qlsl.androiddesign.http.xutils.Protocol;
import qlsl.androiddesign.thread.HandlerThread;
import qlsl.androiddesign.view.baseview.FunctionView;

/**
 * 商家发布模块 <br/>
 * 
 */
public class ShoppingReleaseService extends BaseService {

	private static String className = getClassName(ShoppingReleaseService.class);

	public static void insertShopping(final String sumcierid,
			final List<HashMap<String, String>> list,
			final FunctionView<?> functionView, final HttpListener listener) {
		final HttpHandler handler = getHandler(functionView, listener,
				className, "insertShopping");
		new HandlerThread(className, "insertShopping") {
			public void run() {
				HttpProtocol protocol = new HttpProtocol();
				try {
					protocol.setMethod("publishgoods");
					for (HashMap<String, String> map : list) {
						protocol.addParam(map.get("key"), map.get("value"));
					}
					JSONObject jo = protocol.addParam("sumcierid", sumcierid)
							.post();
					if (isDataInvalid(jo, handler, protocol)) {
						return;
					}

					Object object = JSON.toJavaObject(jo, Object.class);

					handler.sendMessage(protocol,
							WhatConstant.WHAT_NET_DATA_SUCCESS, object);
				} catch (Exception e) {
					e.printStackTrace();
					handler.sendMessage(protocol, WhatConstant.WHAT_EXCEPITON,
							e);
				}
			};
		}.start();
	}
}
